package com.xhl.robot.listeners;

import cc.moecraft.icq.PicqBotX;
import cc.moecraft.icq.event.EventHandler;
import cc.moecraft.icq.event.IcqListener;
import cc.moecraft.icq.event.events.message.EventPrivateMessage;
import cc.moecraft.icq.sender.IcqHttpApi;
import cc.moecraft.icq.sender.message.MessageBuilder;
import cc.moecraft.icq.sender.message.components.ComponentImageBase64;
import cc.moecraft.icq.sender.returndata.ReturnData;
import cc.moecraft.icq.sender.returndata.ReturnListData;
import cc.moecraft.icq.sender.returndata.returnpojo.get.RGroup;
import cc.moecraft.icq.sender.returndata.returnpojo.get.RLoginInfo;
import cc.moecraft.icq.sender.returndata.returnpojo.get.RStrangerInfo;
import cc.moecraft.icq.sender.returndata.returnpojo.send.RMessageReturnData;
import cc.moecraft.icq.user.User;
import com.google.gson.JsonElement;

/**
 * 此类由 Hykilpikonna 在 2018/05/24 创建!
 * Created by Hykilpikonna on 2018/05/24!
 * Github: https://github.com/hykilpikonna
 * QQ: admin@moecraft.cc -OR- 871674895
 *
 * @author Hykilpikonna
 */
//私聊消息事件监听器
public class EventPrivateMessageListener extends IcqListener {
    @EventHandler
    public void onPMEvent(EventPrivateMessage event) {
//        System.out.println("接到消息");

//        User sender = event.getSender();
//        RStrangerInfo info = sender.getInfo();//获取发送人的详细数据(不一定是最新)
//        RStrangerInfo rStrangerInfo = sender.refreshInfo(true);//刷新发送人的详细数据，是否不用缓存
//        long id = sender.getId();//获取发送人的QQ号
//        System.out.println(event.respond("我返回了消息！"));//回复消息

        if (event.getMessage().equals("你是谁?")) {
            event.respond("我是机器人哇!");
        }

        if (event.getMessage().equals("测试给1409613631发Hi")) {
//            JsonElement send = event.getHttpApi().send(
//                    IcqHttpApi.SEND_PRIVATE_MSG,
//                    "user_id", 1409613631,
//                    "message", "hi",
//                    "auto_escape", false);

            ReturnData<RMessageReturnData> hi = event.getHttpApi().sendPrivateMsg(1409613631, "hi");
        }

        //getBot 获取机器人的各项信息
        if (event.getMessage().equals("测试回复数据")) {
            PicqBotX bot = event.getBot();

            // 测试成功 #1: 普通泛型
            ReturnData<RLoginInfo> returnData = bot.getAccountManager().getNonAccountSpecifiedApi().getLoginInfo();
            bot.getLogger().log("Return Data = " + returnData);

            // 测试 #2: List泛型
            ReturnListData<RGroup> returnListData = bot.getAccountManager().getNonAccountSpecifiedApi().getGroupList();
            bot.getLogger().log("Return List Data = " + returnListData);
        }

        //复杂的消息建造
        if (event.getMessage().equals("测试MessageBuilder")) {
            event.respond(new MessageBuilder()
                    .add("我是第一行")
                    .newLine()
                    .add("我是第二行")
                    .newLine()
                    .add("我是第三行")
                    .add("我没换行")
                    .toString());
        }

        //酷Q pro 才能使用
        if (event.getMessage().equals("测试MessageBuilder图片")) {
            event.respond(new MessageBuilder()
                    .add("图片前面的消息").newLine()
                    .add(new ComponentImageBase64("iVBORw0KGgoAAAANSUhEUgAAABQAAAAVCAIAAADJt1n/AAAAKElEQVQ4EWPk5+RmIBcwkasRpG9UM4mhNxpgowFGMARGEwnBIEJVAAAdBgBNAZf+QAAAAABJRU5ErkJggg==")).newLine()
                    .add("图片后面的").newLine()
                    .add("换行之后的消息")
                    .toString());
        }
    }
}
